<template>
    <div class="shopDetails warp">
        <div class="content_Box">
            <div class="left_img">
                <div class="pic">
                    <img  :src="imgurls+imagesItem"/> 
                    <!-- 鼠标层罩 -->
                    <div v-show="topShow" class="top" :style="topStyle"></div>
                    <!-- 最顶层覆盖了整个原图空间的透明层罩 -->
                    <div class="maskTop" @mouseenter="enterHandler" @mousemove="moveHandler" @mouseout="outHandler"></div>
                </div>
                <div class="pic_list">
                    <i @click="go(1)" class="el-icon-arrow-left left_btn"></i>
                    <div class="pic_con">
                        <ul class="pic_ul" :style="changePic">
                            <li v-for="(val,i) in shopObj.images" :key="i" @click="imageShow(i)"> 
                                <div class="img_box">
                                    <img :src="imgurls+val"/>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <i @click="go(-1)" class="el-icon-arrow-right right_btn"></i>
                </div>     
            </div>
            <div class="right_Specifics">
                <div v-show="rShow" class="right">
                    <img :style="r_img" class="rightImg" :src="imgurls+imagesItem" alt="">
                </div>

                <div class="row_title">
                    <div class="top_left">
                        <div  v-if="shopObj.is_business==1" class="info_status buleBtn">
                            <span>出租</span>
                        </div>
                        <div  v-if="shopObj.is_business==2" class="info_status greenBtn">
                            <span>出售</span>
                        </div>
                        <div v-if="shopObj.is_business==3" class="info_status redBtn">
                            <span>求租</span>
                        </div>
                        <div  v-if="shopObj.is_business==4" class="info_status yellowBtn">
                            <span>求购</span>
                        </div>

                        <!-- <div class="info_status yellowBtn">出售</div> -->
                        <div class="name">{{shopObj.name}}</div>
                    </div>
                    <div class="top_right">
                        <!-- <div class="info_number">物资编号：11198693</div>
                        <div class="info_phone">
                            <img src="@/assets/phone24.png" alt="">
                            400-056-887 
                        </div> -->
                    </div>
                </div>
                <div class="row_money">
                    <span class="label">价&nbsp;&nbsp;格：</span>
                    <span class="price red">{{shopObj.transaction_price}}</span>
                </div>
                <div class="row_Specifics">
                    <el-row class="items">
                        <el-col :span="8">
                            <div class="lable">物资名称</div>
                            <div class="value">{{shopObj.name}}</div>
                        </el-col>
                        <el-col :span="8">
                            <div class="lable">规格型号</div>
                            <div class="value">{{shopObj.specification}}</div>
                        </el-col>
                        <el-col :span="8">
                            <div class="lable">截止日期</div>
                            <div class="value">{{shopObj.sell_date}}</div>
                        </el-col>
                    </el-row>
                    <el-row class="items">
                        <el-col :span="8">
                            <div class="lable">存放方式</div>
                            <div class="value">{{shopObj.storage}}</div>
                        </el-col>
                        <el-col :span="8">
                            <div class="lable">所在地区</div>
                            <div class="value">{{shopObj.location}}</div>
                        </el-col>
                        <el-col :span="8">
                            <div class="lable">数量</div>
                            <div class="value">{{shopObj.total_supply}}</div>
                        </el-col>
                    </el-row>
                    <el-row class="items">
                        <el-col :span="8">
                            <div class="lable">结算方式</div>
                            <div class="value">{{shopObj.settlement}}</div>
                        </el-col>
                        <el-col :span="8">
                            <div class="lable">是否含税</div>
                            <div class="value">{{shopObj.tax_included_info}}</div>
                        </el-col>
                        <el-col :span="8">
                            <div class="lable">运输费用</div>
                            <div class="value">{{shopObj.transport_cost}}</div>
                        </el-col>
                    </el-row>
                </div>
                <div class="row_download">
                    <i class="el-icon-picture"></i>
                    下载图集.zip
                </div>
                <div class="row_phone">
                    <div class="btn" @click="phoneBtnEvent"><i class="el-icon-service"></i>在线咨询</div>
                </div>
            </div>
        </div>
        <div class="materialPic_box">
            <v-tip
                :content="'物资照片'"   
                :font-size="22"
            />
            <div class="detail_img">
                <div  v-for="(val,i) in shopObj.images" :key="i">
                    <img :src="imgurls+val" alt="">
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import {wasteDetails} from '@/api/interface'
import vTip from '@/components/title/a-tip.vue'
export default {
    components:{
        vTip
    },
    data(){
        return{
            shopObj:{},
            imagesItem:'',
            topShow:false,
            topStyle: { transform: '' },
            rShow: false,
            r_img: {},

            imagesArylots:['/storage/upload/pictureDownload/2023100810513400000018711.jpg',
            '/storage/upload/pictureDownload/2023100811073200000031471.jpg'],
            imgList:['../../../../assets/shopping/1437dcf67139.jpg','@/assets/shopping/1437dcf67139.jpg']
        }
    },
    computed: {
      changePic() {
        return {
          transform: `translate3d(${this.width}px, 0, 0)`, //主要实现核心
        };
      },
    },
    created(){
        let query = this.$route.query;
        this.getShopDetails(query.wasteId);
    },
    methods:{
        getShopDetails(id){
            wasteDetails({id:id}).then((res)=>{
                this.shopObj =  res.data;
                this.imagesItem = res.data.images[0];
            });
        },
        //图片列表点击事件
        imageShow(i){
            this.imagesItem = this.shopObj.images[i];
        },
        //图片列表-下一个 上一个
        go(direc) {
            if (direc == -1) {
            this.index = this.index >= this.imagesArylots.length - 1 ? 0 : this.index + 1;
            } else if (direc == 1) {
            this.index = this.index <= 0 ? this.imagesArylots.length - 1 : this.index - 1;
            }
            // console.log("index:", this.index);
            this.move(); //移动
        },
        //图片列表移动
        move() {
            this.width = -148 * this.index;
            // console.log("width:", this.width);
        },
        // 图片点击放大
        enterHandler() {
            // 层罩及放大空间的显示
            this.topShow = true;
            this.rShow = true;
        },
        // 鼠标移动函数
        moveHandler(event) {
            // 鼠标的坐标位置
            let x = event.offsetX
            let y = event.offsetY
            // 层罩的左上角坐标位置，并对其进行限制：无法超出原图区域左上角
            let topX = x - 100 < 0 ? 0 : x - 100
            let topY = y - 100 < 0 ? 0 : y - 100
        
            // 对层罩位置再一次限制，保证层罩只能在原图区域空间内
            if (topX > 250) {
                topX = 250
            }
            if (topY > 190) {
                topY = 190
            }
            // 通过 transform 进行移动控制
            this.topStyle.transform = `translate(${topX}px,${topY}px)`
            this.r_img.transform = `translate(-${2 * topX}px,-${2 * topY}px)`
        },
        // 鼠标移出函数
        outHandler() {
            // 控制层罩与放大空间的隐藏
            this.topShow = false;
            this.rShow = false;
        },
        phoneBtnEvent(){
            this.$alert('联系电话：18731185621', {
                confirmButtonText: '确定',
                center: true,
            });
        },
    }
}
</script>
<style lang="less" scoped>
@import '@/styles/index.less';
.shopDetails{
    min-height: 100vh;
    .content_Box{
        display: flex;
        justify-content: space-between;
        margin-top: 30px;
        background-color: #fff;
        border-radius: 8px;
        padding: 26px;
       .left_img{
            .pic{
                position: relative;
                .top {
                    width: 250px;
                    height: 190px;
                    background-color: lightcoral;
                    opacity: 0.4;
                    position: absolute;
                    top: 0;
                    left: 0;
                }
                .maskTop {
                    width: 500px;
                    height: 380px;
                    position: absolute;
                    z-index: 1;
                    top: 0;
                    left: 0;
                }
                img{
                    width: 500px;
                    height: 380px;
                }
            }
            .pic_list{
                width: 410px;
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-top:10px;
                padding: 5px;
                .pic_con{
                    width: 700px;
                    overflow:hidden;
                    margin: 0 13px;
                    .pic_ul{
                        display: flex;
                        height: 124px;
                        line-height: 124px;
                        transition: 0.5s ease;
                        li{
                            padding: 5px;
                            height: 124px;
                            .img_box{
                                display: block;
                                width: 140px; 
                                height: 110px;
                                // overflow: hidden;
                                img{
                                    width: 100%;
                                    height: 100%;
                                    object-fit: contain;
                                }
                                video{
                                    width: 100%;
                                    height: 100%;
                                }
                            }
                        }
                    }
                }
                .left_btn{
                    font-size: 40px;
                    color: #ccc;
                }
                .right_btn{
                    font-size: 40px;
                    color: #ccc;
                }
            }
       }
    
       //图片右侧内容样式
       .right_Specifics{
            width: 600px;
            position: relative;
            .right {
                position: absolute;
                top: 0;
                left: 0;
                width: 500px;
                height: 380px;
                border: 1px solid red;
                overflow: hidden;
                background: #fff;
                .rightImg {
                    display: inline-block;
                    width: 1000px;
                    height: 760px;
                    position: absolute;
                    top: 0;
                    left: 0;
                    z-index: 9999;
                }
            }
            .row_title{
                display: flex;
                justify-content: space-between;
                .top_left{
                    display: flex;
                    align-items: center;
                    .info_status{
                        height: 24px;
                        line-height: 24px;
                        margin-right: 12px;
                        padding: 0 12px;
                        // background: @base-color;
                        border-radius: 0 15px 15px 0;
                        font-size: 12px;
                        font-weight: 400;
                        color: #fff;
                    }
                    .name{
                        flex: 1;
                        font-size: 20px;
                        font-weight: 600;
                        color: #333;
                        padding-right: 28px;
                    }
                }
                .top_right{
                    display: flex;
                    align-items: center;
                    .info_number{
                        margin-right: 54px;
                        font-size: 12px;
                        font-weight: 400;
                        color: #666;
                        line-height: 12px;
                    }
                    .info_phone{
                        display: flex;
                        align-items: center;
                        font-size: 12px;
                        color: #333;
                        line-height: 12px;
                        img{
                            display: block;
                            width: 20px;
                            height: 20px;
                            margin-right: 6px;
                        }
                       
                    }
                }
            }
            .row_money{
                padding: 24px 0;
                .label{
                    font-size: 16px;
                    font-weight: 400;
                    color: #666;
                }
                .price{
                    font-weight: 700;
                    font-size: 24px;
                    line-height: 20px;
                    padding-right: 4px;
                }
            }
            .row_Specifics{
                background: rgba(18,93,178,.08);
                border-radius: 8px;
                padding: 0 21px;
                margin-bottom: 16px;
                .items:not(:last-child){
                    border-bottom: 1px dashed #e4e8f0;
                }
                .items{
                    min-height: 75px;
                    padding: 20px 0 16px;
                    .lable{
                        font-size: 14px;
                        font-weight: 400;
                        color: #999;
                        line-height: 14px;
                        padding-bottom: 8px;
                    }
                    .value{
                        font-size: 14px;
                        font-weight: 500;
                        color: #333;
                        line-height: 14px;
                    }
                }
            }
            .row_download{
                display: flex;
                align-items: center;
                margin-bottom: 41px;
                font-size: 14px;
                font-weight: 500;
                color: #37f;
                line-height: 14px;
                .el-icon-picture{
                    font-size: 24px;
                }
            }
            .row_phone{
                .btn{
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    width: 108px;
                    height: 32px;
                    background: @base-color;
                    border-radius: 5px;
                    font-size: 14px;
                    font-weight: 500;
                    color: #fff;
                    line-height: 14px;
                    box-sizing: border-box;
                    cursor: pointer;
                    .el-icon-service{
                        font-size: 20px;
                        margin-right: 6px;
                    }
                }
            }
       }
    }
    //物资图片
    .materialPic_box{
        margin: 30px 0;
        background-color: #fff;
        border-radius: 8px;
        padding: 10px;
        .detail_img{
            margin-top: 20px;
            display: grid;
            justify-content: space-between;
            grid-template-columns: repeat(auto-fill,382px);
            grid-gap: 12px;
            div{
                img{
                width: 382px;
                height: 246px;
                border-radius: 8px;
            }
            }
            
        }
        
    }
}
</style>